package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @description: 供应商管理
 * @author:
 * @date: 2023/2/5 21:22
 * @version: v1.0
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    /**
     * @description: 供应商列表展示
     * @author
     * @date 2023/2/6 9:34
     */
    @PostMapping("/list")
    public Map<String,Object> getSupplierList(Integer page,Integer rows,String supplierName){
        return supplierService.getSupplierList(page,rows,supplierName);
    }

    /**
     * @description: 供应商添加和修改
     * http://localhost:8080/supplier/save?添加的请求
     * http://localhost:8080/supplier/save?supplierId=1 修改的请求
     * @author
     * @date 2023/2/6 9:35
     */
    @PostMapping("/save")
    public ServiceVO save(Supplier supplier){
       int result= supplierService.save(supplier);
       return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);

    }

    /**
     * @description:供应商删除的接口（支持批量删除）
     * http://localhost:8080/supplier/delete
     * @author
     * @date 2023/2/10 8:26
     */
    @PostMapping("/delete")
    public ServiceVO delete(String ids){
        supplierService.delete(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }
}
